package com.walle.concurrenttest;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest
 * @Description: ${todo}
 * @date 2019/2/18 9:55
 */
public class BankThread implements Runnable {


    private Bank bank;

    public BankThread(Bank bank) {
        this.bank = bank;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        boolean success = bank.withdraw(100);
        String threadName = Thread.currentThread().getName();
        if(success){
            System.out.println(String.format("%s取钱成功!",threadName));
        }else {
            System.out.println(String.format("%s取钱失败!",threadName));
        }
    }
}
